import { request } from "@/utils/request";

export interface UserInfo {
    id: string;
    username: string;
    password: string;
    gender: "male" | "female" | "other";
    email: string;
    avatar: string;
}

export const getUserAPI = (id: string) => {
    return request.get({ url: `/users/${id}` });
};

export const getUsersAPI = (page: number = 1, pageSize: number = 10, isPageable: boolean = true) => {
    return request.get({ url: "/users", params: isPageable ? { _page: page } : {} });
};

export const getAllUsersAPI = () => {
    return request.get({ url: "/users" });
};

export const addUserAPI = (data: Partial<UserInfo>) => {
    return request.post({
        url: "/users",
        data: { ...data, avatar: `https://api.dicebear.com/9.x/bottts-neutral/svg?seed=${Date.now()}` }
    });
};

export const updateUserAPI = (data: Partial<UserInfo>) => {
    return request.put({ url: `/users/${data.id}`, data });
};

export const deleteUserAPI = (id: string) => {
    return request.delete({ url: `/users/${id}` });
};
